package com.crm.business.examine.service.impl;

import com.crm.business.examine.service.ExamineService;
import com.crm.business.examine.service.IExamineRecordLogService;
import com.crm.business.examine.service.IExamineRecordService;
import com.crm.business.examine.service.IExamineService;
import com.crm.common.examine.entity.PO.Examine;
import com.crm.common.ka.core.feign.examine.entity.ExamineRecordLogBo;
import com.crm.common.ka.core.feign.examine.entity.ExamineInfoVo;
import com.crm.common.ka.core.feign.examine.entity.ExamineRecordReturnVO;
import com.crm.common.ka.core.feign.examine.entity.ExamineRecordSaveBO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ExamineCallServiceImpl implements ExamineService {

    @Autowired
    private IExamineRecordService examineRecordService;
    @Autowired
    private IExamineService examineService;
    @Autowired
    private IExamineRecordLogService examineRecordLogService;
    @Autowired
    private ExamineService exService;

    public ExamineRecordReturnVO addExamineRecord(ExamineRecordSaveBO examineRecordSaveBO){
        ExamineRecordReturnVO examineRecordVO = examineRecordService.addExamineRecord(examineRecordSaveBO);
        return examineRecordVO;
    }

    public List<ExamineInfoVo> queryNormalExamine(Integer label){
        List<Examine> examineList = examineService.lambdaQuery().eq(Examine::getLabel, label).eq(Examine::getStatus, 1).list();
        List<ExamineInfoVo> result = new ArrayList<>();
        for(Examine examine : examineList){
            ExamineInfoVo vo = new ExamineInfoVo();
            BeanUtils.copyProperties(examine,vo);
            result.add(vo);
        }
        return result;
    }

    public ExamineRecordLogBo queryExamineLogById(Integer examineLogId){
        return exService.queryExamineLogById(examineLogId);
    }

    public ExamineRecordReturnVO queryExamineRecordInfo(Integer recordId){
        return examineRecordService.queryExamineRecordInfo(recordId);
    }

    public ExamineInfoVo queryExamineById(Long examineId){
        Examine examine = examineService.getById(examineId);
        ExamineInfoVo vo = new ExamineInfoVo();
        BeanUtils.copyProperties(examine,vo);
        return vo;
    }

    public Boolean deleteExamineRecord(Integer recordId){
        return examineRecordService.deleteExamineRecord(recordId);
    }

    public Boolean updateExamineRecord(Integer recordId, Integer examineStatus){
        return examineRecordService.updateExamineRecord(recordId,examineStatus);
    }

    public List<Integer> queryOaExamineIdList(Integer status, Integer categoryId){
        return examineService.queryOaExamineIdList(status,categoryId);
    }

    public List<Integer> queryCrmExamineIdList(Integer label, Integer status){
        return examineService.queryCrmExamineIdList(label,status);
    }

    public Boolean deleteExamineRecordAndLog(Integer label){
        return examineRecordService.deleteExamineRecordAndLog(label);
    }
}
